/*
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
9 = 7 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

Anser:5777
Time:850.129µs
*/
package main

import (
	"fmt"
	"time"
)

func main() {
	tstart := time.Now()
	const bound = 1e4
	s := [bound]bool{true, true}
	for i := 2; i < bound; i++ {
		for j := 2; j < bound/i; j++ {
			s[i*j] = true
		}
	}
	for i := 3; i < bound; i += 2 {
		if s[i] {
			ok := true
			for j := 1; i-2*j*j > 0; j++ {
				if !s[i-2*j*j] {
					ok = false
					break
				}
			}
			if ok {
				fmt.Println(i)
				break
			}
		}
	}
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}
